import instance from "../url/admin.js";
import { success, failure ,warning} from "../static/js/alert.js";


// 首页推荐
const update_index_rec = async (files,date,title) => {
            let form = new FormData()
            let id = 0
            files.forEach((file)=>{
                form.append(`file${id}`, file)
                id+=1
            })
            form.append('title', title)
            form.append('files', id)
            form.append('date', date)
    return await instance.post(`/index/rec/f`, form,
        {
            headers:
                { 'Content-Type': 'multipart/form-data' }
        
        }
     )
        .then((response) => {
            if (response == 1) {
                success()
                return 1
                
            } else { 
                failure()
            }           
        })
}
const delete_index_rec = async (id) => { 
    return await instance.post(`/index/rec/f_d?id=${id}`).then((response) => { 
        if (response == 1) { 
            success("删除成功!")
        }
        else { 
            failure()
        }
    })
}


const put_writer_swiper_data = async (DATA) => { 
    return await instance.post(`/put/writer/index/swiper`, {
        DATA
    })
    .then((response) => {
        return response
})
}
const get_writer_swiper_data = async (limit=1) => { 
    return await instance.get(`/get/writer/index/swiper?limit=${limit}`)
        .then((response) => {
        return response
    })
}
const delete_writer_swiper_data= async (id) => { 
    return await instance.post(`/delete/writer/index/swiper?id=${id}`)
        .then((response) => {
        return response
    })
}



export {
    update_index_rec, delete_index_rec,
    put_writer_swiper_data,get_writer_swiper_data,delete_writer_swiper_data

}